home *** CD-ROM | disk | FTP | other *** search
- Path: rubens.telebyte.nl!news
- From: Christ van Willegen <cvw@spc.nl>
- Newsgroups: comp.lang.c++
- Subject: Writing AVI problems
- Date: Thu, 04 Apr 1996 10:58:45 +0100
- Organization: SPC Vision b.v.
- Message-ID: <31639D55.2FCB@spc.nl>
- NNTP-Posting-Host: 193.67.232.34
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 2.0GoldB1 (Win95; I)
-
- Hi,
-
- First, let me introduce myself. I'm a programmer who works at a company
- that produces multi-media CD-ROM and CD-i titles.
-
- I am currently busy writing a program that can generate an AVI file from
- a bunch of image files, and an audio file.
-
- The video part works correctly, and I can write correct video streams.
- The problems start when I want to write the Audio and Video streams
- together.
-
- THe program consists of two parts. In the first part, I construct a video
- stream from the external graphics files. In the second part, I re-open
- the video stream I just created, open the audio file (standard .WAV file)
- and open a new AVI file, with a video and an audio stream.
-
- Then, I read the Video and Audio data in a loop, and write the data to the
- two new streams. The loop looks like this. I hope the variable names are
- clear enough:
-
- Raw=(unsigned char *)malloc(200*1024);
-
- // Then, read data from the audio and video streams
- // opened above (AVIStreamRead)
- // Write the multi-media data to the new AVI file (AVIStreamWrite)
-
- Sample=0;
- AudioSample=0;
- BytesWritten=0;
-
- do
- {
- hr=AVIStreamRead (pvs, Sample, 1, Raw, 200*1024,
- &BytesRead, &SamplesRead);
- hr=AVIStreamWrite(pvs2,Sample, SamplesRead, Raw, 200*1024,
- (Sample%KeyFrames)?0:AVIIF_KEYFRAME, &SamplesWritten, &BytesWritten);
-
- hr=AVIStreamRead (pas, AudioSample, SamplesRead*
- pFormat->nSamplesPerSec/(Scripting?10:Fps)/pFormat->nBlockAlign,
- Raw, 200*1024, &BytesRead, &AudioSamplesRead);
- hr=AVIStreamWrite(pas2,AudioSample, AudioSamplesRead, Raw, 200*1024,
- AVIIF_KEYFRAME, &AudioSamplesWritten, &BytesWritten);
-
- Sample+=SamplesRead;
- AudioSample+=AudioSamplesRead;
-
- } while (SamplesRead);
-
- // Close the files!
-
- Raw is a buffer to hold the data;
- Sample is the video sample I'm at
- AudioSample is the audio sample I'm at
- KeyFrames is the 'distance' between two keyframes
- Scripting tells me if I'm using a script file for writing the AVI file. If so, I'm using
- 10 Fps, else the value in Fps
- Pas and Pas2 are pointers to audio streams.
- Pvs and Pvs2 are pointers to video stream.
-
- The 'hr' variable is (clearly) there for debugging purposes.
- After both AVIStreamWrite()'s, hr equals the value 0x8000ffff, which is an undocumented
- error (Error = 0xbfff). The value of BytesWritten never changes!
-
- Afterwards, the resulting AVI file has 1 video stream, with the correct data, and no
- audio streams.
-
- If anyone can shed some light on this problem, that would help me a lot! I can mail/post
- more source if that's needed.
-
- Please e-mail to me, and I'll summarise in the group, as I usually don't read it.
-
- Thanks in advance!
-
- Christ van Willegen
-